"""
Description: 配置文件
Author: 嘎嘣脆的贝爷
Date: 2024-11-05 17:26:21
LastEditTime: 2024-11-05 17:27:12
LastEditors: 嘎嘣脆的贝爷
"""

from dotenv import load_dotenv, find_dotenv
import os


class Config:
    """
    配置文件
    """

    def __init__(self):
        # 加载环境变量
        load_dotenv(find_dotenv(), override=True)
        # 切换到证书路径
        os.chdir(os.getenv("CERT_PATH") or "./")

        self.ACCESS_KEY_ID = os.getenv("ALI_ACCESS_KEY_ID")
        self.ACCESS_KEY_SECRET = os.getenv("ALI_ACCESS_KEY_SECRET")
        self.DOMAIN_LIST = os.getenv("DOMAIN_LIST")

        # 检查参数
        if not self.DOMAIN_LIST:
            raise ValueError("请设置要监测的域名列表")
        try:
            self.DOMAIN_LIST = eval(self.DOMAIN_LIST)
        except Exception as e:
            print(e)
            raise ValueError("域名列表格式错误")
        if not (self.ACCESS_KEY_ID and self.ACCESS_KEY_SECRET):
            raise ValueError(
                "环境变量 ALI_ACCESS_KEY_ID 和 ALI_ACCESS_KEY_SECRET 未配置"
            )

    # 产品代码
    PRODUCT_CODE = "digicert-free-1-free"
    # 过期时间阈值
    EXPIRE_THRESHOLD = 3 * 24 * 60 * 60
    # 每轮循环检测间隔时间，单位为秒，默认为20
    DELAY = 20
    # 是否布置了 dcdn 证书
    USE_DCDN = False


config = Config()
